/*
 * File: SOCE.c
 *
 * Code generated for Simulink model 'SOCE'.
 *
 * Model version                  : 3.289
 * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
 * C/C++ source code generated on : Sun Dec 31 11:58:56 2023
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: NXP->Cortex-M4
 * Code generation objective: MISRA C:2012 guidelines
 * Validation result: Not run
 */

#include "SOCE.h"
#include "SOCE_private.h"
#include "RTE.h"
#include "look1_iu16lu16n16_binlcase.h"

/* Named constants for Chart: '<S5>/CorrectSOC' */
#define IN_Calc                        ((uint8_T)1U)
#define IN_Empty                       ((uint8_T)2U)
#define IN_Empty1                      ((uint8_T)3U)
#define IN_Full                        ((uint8_T)4U)
#define IN_NO_ACTIVE_CHILD             ((uint8_T)0U)
#define IN_UpdateNOM                   ((uint8_T)5U)
#define IN_UpdateNOM1                  ((uint8_T)6U)
#define IN_init                        ((uint8_T)7U)

/* Named constants for Chart: '<S5>/DeltaSOC' */
#define IN_Error                       ((uint8_T)1U)
#define IN_Init                        ((uint8_T)2U)
#define IN_ON                          ((uint8_T)1U)
#define IN_Startup                     ((uint8_T)2U)

/* Named constants for Chart: '<S5>/RealSOC' */
#define IN_Fulll                       ((uint8_T)2U)
#define IN_UpdateNOM1_a                ((uint8_T)4U)
#define IN_UpdateNOM_i                 ((uint8_T)3U)
#define IN_init_g                      ((uint8_T)5U)

/* Named constants for Chart: '<S5>/socUpK' */
#define IN_Init1                       ((uint8_T)1U)
#define IN_SchglongTripMode            ((uint8_T)2U)

/* Block signals (default storage) */
B_SOCE_T SOCE_B;

/* Block states (default storage) */
DW_SOCE_T SOCE_DW;

/* Real-time model */
static RT_MODEL_SOCE_T SOCE_M_;
RT_MODEL_SOCE_T *const SOCE_M = &SOCE_M_;

/* Exported data definition */

/* Definition for custom storage class: ExportToFile */
uint8_T currv_fact_k = ((uint8_T)0U);  /* '<S5>/Delay' */
uint32_T soce_ah_Mas = 0U;             /* '<S5>/CorrectSOC' */
uint32_T soce_ah_RealMas = 0U;         /* '<S5>/RealSOC' */
uint32_T soce_mas_nomAh = 0U;          /* '<S29>/Product' */
uint16_T soce_pct_DispSOC = ((uint16_T)0U);/* '<S5>/OCVTableHi2' */
uint8_T soce_pct_DymCorrSts = ((uint8_T)0U);/* '<S5>/Delay5' */
uint16_T soce_pct_RealSOC = ((uint16_T)0U);/* '<S5>/Saturation2' */
uint16_T soce_pct_SOC = ((uint16_T)0U);/* '<S5>/Saturation1' */
uint16_T soce_pct_deltaSoc = ((uint16_T)1U);/* '<S5>/Constant1' */

/* Forward declaration for local functions */
static void inner_default_ON(const uint16_T *Delay3, const uint8_T *Delay2);
static uint32_T Nom_Cal(uint16_T in_soc, uint32_T in_mas, int32_T delta_ah);
static uint16_T Abs_Diff(uint16_T tmp1, uint16_T tmp2);
static uint8_T Limit_DK(uint16_T b_min, uint16_T b_max, const uint16_T *sDK);

/* Function for Chart: '<S5>/DeltaSOC' */
static void inner_default_ON(const uint16_T *Delay3, const uint8_T *Delay2)
{
    uint32_T tmp;
    if (SOCE_B.flg)
    {
        if (BMS_TYPE_BATTERY == 0)
        {
            SOCE_B.realSOC = Rte_TAB_enum_SOCOcv_GetVal();
            SOCE_B.update = 3U;
        }
        else
        {
            if ((BMS_TYPE_BATTERY == 1) && (Rte_TAB_enum_SOCOcv_GetVal() <
                    SOC_LPF_LINE) && (Rte_c_CellMinTmp_GetVal() >= 50))
            {
                /* correctsoc1>(OCVTemp+400) */
                SOCE_B.realSOC = Rte_TAB_enum_SOCOcv_GetVal();
                SOCE_B.update = 3U;
            }
        }
    }
    else if (Rte_flg_UpdateCap_GetVal() > 0)
    {
        if (Rte_flg_UpdateCap_GetVal() == 1)
        {
            SOCE_B.correctSOC = Rte_TAB_enum_SOCOcv_GetVal();
            SOCE_B.realSOC = Rte_TAB_enum_SOCOcv_GetVal();
            SOCE_B.update = 1U;
        }
        else if (Rte_flg_UpdateCap_GetVal() == 2)
        {
            SOCE_B.realSOC = SOCE_B.correctSOC;
            SOCE_B.update = 2U;
            if (Rte_mas_set_GetVal() > soce_mas_nomAh)
            {
                SOCE_B.correctSOC = 10000U;
            }
            else
            {
                tmp = soce_mas_nomAh / 10000U;
                SOCE_B.correctSOC = (uint16_T)(tmp == 0U ? MAX_uint32_T :
                    Rte_mas_set_GetVal() / tmp);
            }
        }
        else
        {
            if (Rte_flg_UpdateCap_GetVal() == 3)
            {
                SOCE_B.correctSOC = Rte_pct_SetSOC_GetVal();
                SOCE_B.update = 4U;
            }
        }
    }
    else if ((soce_pct_DymCorrSts > 0) && ((SOCE_DW.corrFlg == 0.0) || (*Delay2 ==
               1)))
    {
        SOCE_B.realSOC = *Delay3;
        SOCE_DW.corrFlg = 1.0;
        SOCE_B.update = 5U;
    }
    else
    {
        if (soce_pct_DymCorrSts == 0)
        {
            SOCE_DW.corrFlg = 0.0;
        }

        SOCE_B.update = 0U;
    }
}

/* Function for Chart: '<S5>/CorrectSOC' */
static uint32_T Nom_Cal(uint16_T in_soc, uint32_T in_mas, int32_T delta_ah)
{
    uint32_T output;
    if (delta_ah > 0)
    {
        if (in_mas > (uint32_T)delta_ah)
        {
            output = in_mas - delta_ah;
        }
        else
        {
            output = 0U;
        }
    }
    else
    {
        if (in_soc <= Pccfg_ChgSOCLim - 60)
        {
            output = in_mas - delta_ah;
        }
        else
        {
            output = in_mas;
        }

        if (in_mas > soce_mas_nomAh)
        {
            output = soce_mas_nomAh;
        }
    }

    return output;
}

/* Function for Chart: '<S5>/socUpK6' */
static uint16_T Abs_Diff(uint16_T tmp1, uint16_T tmp2)
{
    uint16_T output;
    if (tmp1 > tmp2)
    {
        output = (uint16_T)(tmp1 - tmp2);
    }
    else
    {
        output = (uint16_T)(tmp2 - tmp1);
    }

    return output;
}

/* Function for Chart: '<S5>/socUpK6' */
static uint8_T Limit_DK(uint16_T b_min, uint16_T b_max, const uint16_T *sDK)
{
    uint8_T k;
    if (*sDK <= b_min)
    {
        k = (uint8_T)b_min;
    }
    else if (*sDK >= b_max)
    {
        k = (uint8_T)b_max;
    }
    else
    {
        k = (uint8_T)*sDK;
    }

    return k;
}

/* Model step function */
void TASK_SOCESignal(void)
{
    int32_T Switch8;
    int32_T mas;
    int32_T mas_0;
    int32_T out;
    uint32_T tmp;
    int16_T Add_f;
    int16_T Add_p;
    int16_T Saturation1;
    uint16_T Delay3;
    uint8_T Delay2;
    uint8_T DymSts;
    boolean_T AND_l;
    boolean_T Switch25;
    boolean_T guard1 = false;
    AND_l = (((vewm_enum_SlowChgSts == 4) || (vewm_enum_FastChgSts == 4)) &&
             (vewm_enum_socAlw == 0));
    Saturation1 = (int16_T)((int16_T)((Rte_ma_BatCurr_GetVal() + 500U) / 1000U)
                            - 1000);
    if (Saturation1 > 1000)
    {
        Saturation1 = 1000;
    }
    else
    {
        if (Saturation1 < -1000)
        {
            Saturation1 = -1000;
        }
    }

    if (Rte_c_CellMinTmp_GetVal() > 60)
    {
        Switch25 = (Rte_mv_CellMinVol_GetVal() <= 2400);
    }
    else if (Rte_c_CellMinTmp_GetVal() > 50)
    {
        Switch25 = (Rte_mv_CellMinVol_GetVal() <= 2200);
    }
    else if (Rte_c_CellMinTmp_GetVal() > 40)
    {
        Switch25 = (Rte_mv_CellMinVol_GetVal() <= 1900);
    }
    else if (Rte_c_CellMinTmp_GetVal() > 35)
    {
        Switch25 = (Rte_mv_CellMinVol_GetVal() <= 1800);
    }
    else
    {
        Switch25 = (Rte_mv_CellMinVol_GetVal() <= 1600);
    }

    DelayTimesSe((Saturation1 <= 140) && (vewm_enum_SlowChgSts != 2) && Switch25
                 && (vewm_enum_FastChgSts != 2), &SOCE_B.DelayTimesforS2,
                 &SOCE_DW.DelayTimesforS2, 140);
    if (SOCE_B.DelayTimesforS2.Compare_ih && (SOCE_DW.flg3 == 0))
    {
        DymSts = 8U;
        SOCE_DW.oldsoc3 = 0U;
        SOCE_DW.flg3 = 1U;
    }
    else
    {
        DymSts = 0U;
    }

    soce_mas_nomAh = (uint32_T)Rte_TAB_mas_Nmcpv_GetVal() * Rte_pct_SOH_GetVal()
        * 360U;
    if (Rte_flg_MaiRlySts_GetVal())
    {
        Switch8 = 1000000 - (int32_T)Rte_ma_BatCurr_GetVal();
    }
    else
    {
        Switch8 = 0;
    }

    mas = Switch8 / 1000 * Rte_ms_SOCFre_GetVal();
    SOCE_DW.total += Switch8 % 1000 * Rte_ms_SOCFre_GetVal();
    out = 0;
    if ((SOCE_DW.total >= 50000) || (SOCE_DW.total <= -50000))
    {
        out = SOCE_DW.total;
        SOCE_DW.total %= 1000;
    }

    if (mas < 0)
    {
        mas_0 = -mas;
    }
    else
    {
        mas_0 = mas;
    }

    if (mas_0 > SOC_MAX_DELTA_AH)
    {
        if (mas >= 0)
        {
            mas = SOC_MAX_DELTA_AH;
        }
        else
        {
            mas = 0;
        }
    }

    mas += out / 1000;
    guard1 = false;
    if (BMS_TYPE_BATTERY == 1)
    {
        out = SOC_LPF_WAIT_TIME;
        guard1 = true;
    }
    else
    {
        if (BMS_TYPE_BATTERY == 0)
        {
            out = SOC_SY_WAIT_TIME;
            guard1 = true;
        }
    }

    if (guard1)
    {
        SOCE_B.flg = false;
        if ((Switch8 < 2000) && (Switch8 > -2000))
        {
            SOCE_DW.cnt++;
            if (SOCE_DW.cnt > (uint32_T)out)
            {
                SOCE_DW.cnt = 0U;
                SOCE_B.flg = true;
            }
        }
        else
        {
            SOCE_DW.cnt = 0U;
        }
    }

    soce_pct_DymCorrSts = SOCE_B.DymCorrSts;
    Delay3 = SOCE_B.DymSOC_n;
    Delay2 = SOCE_B.DymUpdate;
    if (SOCE_DW.is_c4_SOCE == 1)
    {
        inner_default_ON(&Delay3, &Delay2);
    }
    else
    {
        /* case IN_Startup: */
        if (SOCE_DW.finish)
        {
            SOCE_DW.is_Startup = IN_NO_ACTIVE_CHILD;
            SOCE_DW.is_c4_SOCE = IN_ON;
            inner_default_ON(&Delay3, &Delay2);
        }
        else
        {
            switch (SOCE_DW.is_Startup)
            {
              case IN_Error:
                break;

              default:
                /* case IN_Init: */
                if (Rte_pct_InitSOC_GetVal() == 0xFFFF)
                {
                    SOCE_DW.is_Startup = IN_Error;
                    SOCE_DW.finish = true;
                    SOCE_B.realSOC = Rte_TAB_enum_SOCOcvAll_GetVal();
                    SOCE_B.correctSOC = Rte_TAB_enum_SOCOcvAll_GetVal();
                }
                else
                {
                    SOCE_B.correctSOC = Rte_pct_InitSOC_GetVal();
                    if ((Rte_TAB_enum_SOCOcv_GetVal() < SOC_LPF_LINE) &&
                            (Rte_pct_InitSOC_GetVal() >
                             Rte_TAB_enum_SOCOcv_GetVal() + 400) &&
                            (Rte_c_CellMinTmp_GetVal() >= 50))
                    {
                        SOCE_B.realSOC = Rte_TAB_enum_SOCOcv_GetVal();
                    }
                    else
                    {
                        SOCE_B.realSOC = SOCE_B.correctSOC;
                    }

                    SOCE_DW.finish = true;
                }
                break;
            }
        }
    }

    Switch25 = (soce_mas_nomAh != SOCE_DW.Delay1_DSTATE);
    if (SOCE_DW.is_active_c5_SOCE == 0U)
    {
        SOCE_DW.is_active_c5_SOCE = 1U;
        SOCE_DW.is_c5_SOCE = IN_init_g;
        soce_ah_RealMas = soce_mas_nomAh / 10000U * SOCE_B.realSOC;
        SOCE_B.soc = SOCE_B.realSOC;
    }
    else
    {
        guard1 = false;
        switch (SOCE_DW.is_c5_SOCE)
        {
          case IN_Calc:
            if (((SOCE_B.update <= 3) && (SOCE_B.update > 0)) || (SOCE_B.update ==
                 5))
            {
                SOCE_DW.is_c5_SOCE = IN_init_g;
                soce_ah_RealMas = soce_mas_nomAh / 10000U * SOCE_B.realSOC;
                SOCE_B.soc = SOCE_B.realSOC;
            }
            else if (AND_l)
            {
                SOCE_DW.is_c5_SOCE = IN_Fulll;
            }
            else if (Switch25)
            {
                SOCE_DW.is_c5_SOCE = IN_UpdateNOM_i;
            }
            else if (mas < 0)
            {
                if (soce_ah_RealMas > (uint32_T)-mas)
                {
                    soce_ah_RealMas = soce_ah_RealMas + mas;
                }
                else
                {
                    soce_ah_RealMas = 0U;
                }

                guard1 = true;
            }
            else
            {
                if (mas > 0)
                {
                    soce_ah_RealMas = soce_ah_RealMas + mas;
                    if (soce_ah_RealMas > soce_mas_nomAh)
                    {
                        soce_ah_RealMas = soce_mas_nomAh;
                    }

                    guard1 = true;
                }
            }
            break;

          case IN_Fulll:
            if (Switch25)
            {
                SOCE_DW.is_c5_SOCE = IN_UpdateNOM1_a;
            }
            else if (!AND_l)
            {
                SOCE_DW.is_c5_SOCE = IN_Calc;
            }
            else
            {
                if (soce_ah_RealMas < soce_mas_nomAh)
                {
                    soce_ah_RealMas = soce_mas_nomAh;
                    SOCE_B.soc = Pccfg_ChgSOCLim;
                }
            }
            break;

          case IN_UpdateNOM_i:
            if (Switch8 < 0)
            {
                soce_ah_RealMas = (uint32_T)((int32_T)(soce_mas_nomAh / 10000U) *
                    (SOCE_B.soc + 1));
            }
            else
            {
                soce_ah_RealMas = soce_mas_nomAh / 10000U * SOCE_B.soc;
            }

            SOCE_DW.is_c5_SOCE = IN_Calc;
            break;

          case IN_UpdateNOM1_a:
            if (Switch8 < 0)
            {
                soce_ah_RealMas = (uint32_T)((int32_T)(soce_mas_nomAh / 10000U) *
                    (SOCE_B.soc + 1));
            }
            else
            {
                soce_ah_RealMas = soce_mas_nomAh / 10000U * SOCE_B.soc;
            }

            SOCE_DW.is_c5_SOCE = IN_Fulll;
            break;

          default:
            /* case IN_init: */
            SOCE_DW.is_c5_SOCE = IN_Calc;
            break;
        }

        if (guard1)
        {
            tmp = soce_mas_nomAh / 10000U;
            SOCE_B.soc = (uint16_T)(tmp == 0U ? MAX_uint32_T : soce_ah_RealMas /
                                    tmp);
        }
    }

    if (SOCE_B.soc < 10000)
    {
        soce_pct_RealSOC = SOCE_B.soc;
    }
    else
    {
        soce_pct_RealSOC = 10000U;
    }

    currv_fact_k = SOCE_DW.Delay_DSTATE;
    mas = currv_fact_k * mas / 10;
    if (SOCE_DW.is_active_c1_SOCE == 0U)
    {
        SOCE_DW.is_active_c1_SOCE = 1U;
        SOCE_DW.is_c1_SOCE = IN_init;
        soce_ah_Mas = soce_mas_nomAh / 10000U * SOCE_B.correctSOC;
        SOCE_B.soc_i = SOCE_B.correctSOC;
    }
    else
    {
        guard1 = false;
        switch (SOCE_DW.is_c1_SOCE)
        {
          case IN_Calc:
            if (AND_l)
            {
                /* {deltaMas=(bottv_mas_nomAh/10000)*9/5;} */
                SOCE_DW.is_c1_SOCE = IN_Full;
            }
            else if (Switch25)
            {
                SOCE_DW.is_c1_SOCE = IN_UpdateNOM;
            }
            else if ((SOCE_B.update == 1) || (SOCE_B.update == 2) ||
                     (SOCE_B.update == 4))
            {
                SOCE_DW.is_c1_SOCE = IN_init;
                soce_ah_Mas = soce_mas_nomAh / 10000U * SOCE_B.correctSOC;
                SOCE_B.soc_i = SOCE_B.correctSOC;
            }
            else if (soce_pct_DymCorrSts == 8)
            {
                SOCE_DW.is_c1_SOCE = IN_Empty;
                soce_ah_Mas = Nom_Cal(SOCE_B.soc_i, soce_ah_Mas, (int32_T)
                                      (soce_mas_nomAh / 5000U));
                tmp = soce_mas_nomAh / 10000U;
                SOCE_B.soc_i = (uint16_T)(tmp == 0U ? MAX_uint32_T : soce_ah_Mas
                    / tmp);
            }
            else if (soce_pct_DymCorrSts == 5)
            {
                SOCE_DW.is_c1_SOCE = IN_Empty1;
                soce_ah_Mas = Nom_Cal(SOCE_B.soc_i, soce_ah_Mas, -(int32_T)
                                      (soce_mas_nomAh / 10000U));
                tmp = soce_mas_nomAh / 10000U;
                SOCE_B.soc_i = (uint16_T)(tmp == 0U ? MAX_uint32_T : soce_ah_Mas
                    / tmp);
            }
            else if (mas < 0)
            {
                if (soce_ah_Mas > (uint32_T)-mas)
                {
                    soce_ah_Mas = soce_ah_Mas + mas;
                }
                else
                {
                    soce_ah_Mas = 0U;
                }

                guard1 = true;
            }
            else
            {
                if ((mas > 0) && (SOCE_B.soc_i <= Pccfg_ChgSOCLim - 60))
                {
                    soce_ah_Mas = soce_ah_Mas + mas;
                    if (soce_ah_Mas > soce_mas_nomAh)
                    {
                        soce_ah_Mas = soce_mas_nomAh;
                    }

                    guard1 = true;
                }
            }
            break;

          case IN_Empty:
            if (soce_pct_DymCorrSts != 8)
            {
                SOCE_DW.is_c1_SOCE = IN_Calc;
            }
            else
            {
                soce_ah_Mas = Nom_Cal(SOCE_B.soc_i, soce_ah_Mas, (int32_T)
                                      (soce_mas_nomAh / 5000U));
                tmp = soce_mas_nomAh / 10000U;
                SOCE_B.soc_i = (uint16_T)(tmp == 0U ? MAX_uint32_T : soce_ah_Mas
                    / tmp);
            }
            break;

          case IN_Empty1:
            if (soce_pct_DymCorrSts != 5)
            {
                SOCE_DW.is_c1_SOCE = IN_Calc;
            }
            else
            {
                soce_ah_Mas = Nom_Cal(SOCE_B.soc_i, soce_ah_Mas, -(int32_T)
                                      (soce_mas_nomAh / 10000U));
                tmp = soce_mas_nomAh / 10000U;
                SOCE_B.soc_i = (uint16_T)(tmp == 0U ? MAX_uint32_T : soce_ah_Mas
                    / tmp);
            }
            break;

          case IN_Full:
            if (Switch25)
            {
                SOCE_DW.is_c1_SOCE = IN_UpdateNOM1;
            }
            else if (!AND_l)
            {
                SOCE_DW.is_c1_SOCE = IN_Calc;
            }
            else
            {
                if (soce_ah_Mas < soce_mas_nomAh)
                {
                    soce_ah_Mas = soce_mas_nomAh;
                    SOCE_B.soc_i = Pccfg_ChgSOCLim;
                }
            }
            break;

          case IN_UpdateNOM:
            if (Switch8 < 0)
            {
                soce_ah_Mas = (uint32_T)((int32_T)(soce_mas_nomAh / 10000U) *
                    (SOCE_B.soc_i + 1));
            }
            else
            {
                soce_ah_Mas = soce_mas_nomAh / 10000U * SOCE_B.soc_i;
            }

            SOCE_DW.is_c1_SOCE = IN_Calc;
            break;

          case IN_UpdateNOM1:
            if (Switch8 < 0)
            {
                soce_ah_Mas = (uint32_T)((int32_T)(soce_mas_nomAh / 10000U) *
                    (SOCE_B.soc_i + 1));
            }
            else
            {
                soce_ah_Mas = soce_mas_nomAh / 10000U * SOCE_B.soc_i;
            }

            SOCE_DW.is_c1_SOCE = IN_Full;
            break;

          default:
            /* case IN_init: */
            SOCE_DW.is_c1_SOCE = IN_Calc;
            break;
        }

        if (guard1)
        {
            tmp = soce_mas_nomAh / 10000U;
            SOCE_B.soc_i = (uint16_T)(tmp == 0U ? MAX_uint32_T : soce_ah_Mas /
                tmp);
        }
    }

    if (SOCE_B.soc_i < 10000)
    {
        soce_pct_SOC = SOCE_B.soc_i;
    }
    else
    {
        soce_pct_SOC = 10000U;
    }

    guard1 = false;
    if (DymSts != 0)
    {
        SOCE_B.DymSOC_n = 0U;
        if ((DymSts == 6) && (soce_pct_SOC >= SOCE_B.DymSOC_n + 800))
        {
            SOCE_B.DymCorrSts = 6U;
            Delay3 = (uint16_T)(soce_pct_SOC / 50 + 1);
            SOCE_B.DK = Limit_DK(12, 100, &Delay3);
            SOCE_B.DymUpdate = 1U;
        }
        else if ((DymSts == 7) && (soce_pct_SOC >= SOCE_B.DymSOC_n + 400))
        {
            SOCE_B.DymCorrSts = 7U;
            Delay3 = (uint16_T)(soce_pct_SOC / 25 + 1);
            SOCE_B.DK = Limit_DK(12, 200, &Delay3);
            SOCE_B.DymUpdate = 1U;
        }
        else if ((DymSts == 8) && (soce_pct_SOC >= 100))
        {
            SOCE_B.DymCorrSts = 8U;
            SOCE_B.DK = 0U;
            SOCE_B.DymUpdate = 1U;
        }
        else
        {
            guard1 = true;
        }
    }
    else
    {
        guard1 = true;
    }

    if (guard1)
    {
        if ((Abs_Diff(soce_pct_RealSOC, soce_pct_SOC) <= 10) || AND_l)
        {
            SOCE_B.DK = 0U;
            SOCE_B.DymCorrSts = 0U;
        }

        SOCE_B.DymSOC_n = 0U;
        SOCE_B.DymUpdate = 0U;
    }

    Add_p = (int16_T)((int16_T)soce_pct_RealSOC - (int16_T)soce_pct_SOC);
    if (Add_p < 0)
    {
        Add_f = (int16_T)-Add_p;
    }
    else
    {
        Add_f = Add_p;
    }

    if (Add_f > 0)
    {
        if ((boolean_T)((Saturation1 > 0) ^ (Add_p < 0)))
        {
            if ((SOCE_B.DK > 0) && (SOCE_B.DK < 10))
            {
                SOCE_DW.Delay_DSTATE = SOCE_B.DK;
            }
            else
            {
                SOCE_DW.Delay_DSTATE = 8U;
            }
        }
        else if (SOCE_B.DK > 0)
        {
            SOCE_DW.Delay_DSTATE = SOCE_B.DK;
        }
        else
        {
            SOCE_DW.Delay_DSTATE = 12U;
        }
    }
    else
    {
        SOCE_DW.Delay_DSTATE = 10U;
    }

    soce_pct_DispSOC = look1_iu16lu16n16_binlcase(soce_pct_SOC,
        rtCP_OCVTableHi2_bp01Data, rtCP_OCVTableHi2_tableData, 12U);
    if (SOCE_DW.is_c7_SOCE == 1)
    {
        if (vewm_enum_SlowChgSts == 2)
        {
            SOCE_DW.is_c7_SOCE = IN_SchglongTripMode;
            if ((Rte_mv_CellMaxVol_GetVal() >= 3480) && (Saturation1 <= -3) &&
                    (SOCE_DW.socChgStep == 0))
            {
                SOCE_DW.socChgStep = 1U;
            }
            else
            {
                if ((Rte_mv_CellMaxVol_GetVal() >= 3510) && (Saturation1 <= -3) &&
                    (SOCE_DW.socChgStep != 2))
                {
                    SOCE_DW.socChgStep = 2U;
                }
            }
        }
    }
    else
    {
        /* case IN_SchglongTripMode: */
        if (vewm_enum_SlowChgSts != 2)
        {
            SOCE_DW.is_c7_SOCE = IN_Init1;
            SOCE_DW.socChgStep = 0U;
        }
        else if ((Rte_mv_CellMaxVol_GetVal() >= 3480) && (Saturation1 <= -3) &&
                 (SOCE_DW.socChgStep == 0))
        {
            SOCE_DW.socChgStep = 1U;
        }
        else
        {
            if ((Rte_mv_CellMaxVol_GetVal() >= 3510) && (Saturation1 <= -3) &&
                    (SOCE_DW.socChgStep != 2))
            {
                SOCE_DW.socChgStep = 2U;
            }
        }
    }

    soce_pct_deltaSoc = SOCE_ConstB.Constant1;
    SOCE_DW.Delay1_DSTATE = soce_mas_nomAh;
}

/* Model initialize function */
void SOCE_initialize(void)
{
    SOCE_DW.is_c4_SOCE = IN_Startup;
    SOCE_DW.is_Startup = IN_Init;
    SOCE_DW.is_c7_SOCE = IN_Init1;
    soce_pct_deltaSoc = SOCE_ConstB.Constant1;
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
